<?php
ini_set('date.timezone','Asia/Shanghai');
//error_reporting(E_ERROR);

require_once "../lib/Pay.Api.php";


/**
 * 流程：
 * 1、调用统一下单，取得codeUrl，生成二维码
 * 2、用户扫描二维码，进行支付
 * 3、支付完成之后，支付平台通过回调地址通知支付成功
 * 4、在支付成功通知中需要查单确认是否真正支付成功
 */
$input = new UnifiedData();
// 设置订单金额,单位元
$input->SetParam("orderAmt", 1.42);

//设置商户订单号不可重复, 最大长度32位。
$input->SetParam("orderId", date("YmdHis").PayApi::getNonceNumber(4));

$input->SetParam("body", "消费");

$input->SetParam("bindId", "1708082147577006");

$input->SetParam("spbill_create_ip", "110.87.60.97");

$input->SetParam("tranCode", TranCode::$TRAN_CODE_WX_TRADE_PRE_CREATE);


$result = PayApi::unifiedRequest($input);

$url = "";
$payType = "";
if($result['REP_BODY']['rspcode'] == '000000'){
			LOG::INFO("下单成功：".$result['REP_BODY']['orderId']);
			echo "</br>===============下单成功===================</br>";
			$url = $result["REP_BODY"]["codeUrl"];
			echo "============================================</br>";
		} else {
			$payType = urldecode($result['REP_BODY']['rspmsg']);
			LOG::DEBUG("下单失败信息调试");
			
			LOG::DEBUG("响应码：".$result['REP_BODY']['rspcode']);
			LOG::DEBUG("响应信息：".urldecode($result['REP_BODY']['rspmsg']));
			// 下单失败
			echo "</br>==================下单请求失败=====================</br>";
			echo "</br>响应码:".$result['REP_BODY']['rspcode'];
			echo "</br>响应信息:".urldecode($result['REP_BODY']['rspmsg']);
			echo "</br>==============================================</br>";
}



?>

<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1" /> 
    <title>微信扫描支付样例</title>
</head>
<body>
	<div style="margin-left: 10px;color:#556B2F;font-size:30px;font-weight: bolder;">微信扫描支付</div><br/>
	<img alt="扫码支付" src="/example/qrcode.php?data=<?php echo urlencode($url);?>" style="width:150px;height:150px;"/>
	<br/><br/><br/>
	
</body>
</html>